package com.pany.kotlin

/*
*Author:zhang
*Date:2022/4/19
*for 循环介绍
*/
fun main(args: Array<String>) {

    for (i in 1..10) {
        println(" i == $i")
    }

    var array1 = arrayOf(1, 2, 3, 4, 5)
    for ((index, value) in array1.withIndex()) {
        println("${index} is ${value}")
    }
    array1.forEach {
        println(" it == $it") // it 就是 数组里的元素
    }

    array1.forEach (fun(vaule:Int) {
        println(" vaule = = $vaule")
    })

    var a = 3
    while (a > 1) {
        println(" a = $a")
        a--
    }

    println("------\n")
    do {
        println("a == $a")
        a++
    } while (a < 4)
    //return break ;   continue 不执行下面是代码,执行上面的内容

    xxy()
    println("------   ----------")
    for (j in 1..6) {
        println(" j == $j")
        if (j == 5) {
            println(" j == 5 break")
//            return // return 之后 下面的代码就不执行了
            break // break 结束 本循环的代码
        }
    }

    for (x in 1..10) {
        if (x in 3..5) {
            continue
        }
        println("continue x == $x")
    }
}

fun xxy() {
    for (i in 1..5) {
        if (i < 3) println(" return i == $i") else return

    }
}